package com.dogdog.fragment;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import com.android.volley.AuthFailureError;
import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.android.volley.Request.Method;
import com.android.volley.toolbox.StringRequest;
import com.dogdog.activity.R;
import com.dogdog.activity.R.id;
import com.dogdog.activity.R.layout;
import com.dogdog.adapter.RoundUserAdapter;
import com.dogdog.bean.RoundUserInfo;
import com.dogdog.bean.Status;
import com.dogdog.bean.UserId;
import com.dogdog.manager.C;
import com.dogdog.manager.MyApplication;
import com.google.gson.Gson;

import android.app.Fragment;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListView;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

public class Hand_message extends Fragment implements OnItemClickListener {

	private View tab1;
	private RelativeLayout titlebar;
	private TextView title;
	private ListView listView1;
	private List<RoundUserInfo> roundUserInfo;
	private RoundUserAdapter adapter;
	List<String> idList;
	private Gson gson;

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		tab1 = inflater.inflate(R.layout.fragment_main_message, container,
				false);
		initView();
		return tab1;
	}

	private void initView() {
		titlebar = (RelativeLayout) tab1.findViewById(R.id.rl_titlebar);
		title = (TextView) tab1.findViewById(R.id.tv_title);
		title.setText("消息");
		listView1 = (ListView) tab1.findViewById(R.id.listView1);
		idList = Hand_found_location.idList;
		Log.e("idList", idList.get(0) + ":::" + idList.size() + "");
		getRoundUserInfo();
		roundUserInfo = new ArrayList<RoundUserInfo>();
		adapter = new RoundUserAdapter(getActivity(), roundUserInfo);

	}

	public void getRoundUserInfo(){
		JSONArray array=new JSONArray();
		array.put(idList);
		final JSONObject object=new JSONObject();
		
			try {
				object.put("idList", array);
			} catch (JSONException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			Log.e("json格式", object.toString());
			//URL地址暂时还没给出
			
			StringRequest getRoundInfo = new StringRequest(Method.POST,
					C.URL.MarkerLocation, new Response.Listener<String>() {

						@Override
						public void onResponse(String response) {
							gson = new Gson();
							Status s = gson.fromJson(response.toString(),
									Status.class);
							if (s.getState() == 1) {
								Toast.makeText(getActivity(), "获取信息成功",
										Toast.LENGTH_SHORT).show();
								RoundUserInfo userInfo=gson.fromJson(response, RoundUserInfo.class);
							}
						}
					}, new Response.ErrorListener() {

						@Override
						public void onErrorResponse(VolleyError error) {
							// TODO Auto-generated method stub
							Toast.makeText(getActivity(), "获取信息失败",
									Toast.LENGTH_SHORT).show();
						}
					}) {
				@Override
				protected Map<String, String> getParams() throws AuthFailureError {
					Map<String, String> param = new HashMap<String, String>();
					param.put("uid", object.toString());
					return param;
				}
			};
			MyApplication.getHttpQueue().add(getRoundInfo);
			
			
		
			
	}

	@Override
	public void onItemClick(AdapterView<?> parent, View view, int position,
			long id) {
		// TODO Auto-generated method stub

	}
}
